'use strict';

const Controller = require('egg').Controller;

class ProductController extends Controller {
    //获取商品列表
    async list() {
        let {ctx,service} = this;
        console.log(ctx.request.params);
        let {classify_id} = ctx.request.query;
        let list = await service.product.list(classify_id);
        ctx.body = {
            code:1,
            data:list
        }
    } 
    //模糊搜索
    async search(){
        let {ctx,service} = this;
        let {key} = ctx.request.query;
        let list = await service.product.search(key);
        ctx.body = {
            code:1,
            data:list
        }
    }

    //获取
    async detail(){
        let {ctx,service} = this;
        let {id} = ctx.request.query;
        if(id){
            let target = await service.product.detail(id);
            ctx.body = {
                code:1,
                data:target[0]
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数有误'
            }
        }
    }
}

module.exports = ProductController;
